package tool;

import java.util.Hashtable;

import db.SimpleDBListener;
import db.SimpleDBReader;

public class Properties {

	private String filePath;
	private Hashtable properties;

	public Properties(String aFilePath) {
		properties = new Hashtable();
		filePath = aFilePath;
		loadFileContent();
	}
	
	public String getProperty(String key) {
		return (String) properties.get(key);
	}

	private void loadFileContent() {
		SimpleDBReader dbr = new SimpleDBReader(filePath);
		dbr.addListener(new InnerListener());
		dbr.readDB();
	}
	
	private class InnerListener implements SimpleDBListener {
		
		public void processLine(String line) {
			if (line.indexOf('#') > -1) {
				// Ignore
			} else {
				int equalIndex = line.indexOf('=');
				String key = line.substring(0, equalIndex);
				String value = line.substring(equalIndex + 1);
				properties.put(key, value);
			}
		}

		public void readingDone() {
			// Nothing to do
		}
	}
}
